package com.gp.geits.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gp.geits.dao.IssueDao;
import com.gp.geits.entity.IssueEntity;
import com.gp.geits.service.IssueService;
import com.gp.geits.utils.PageUtils;
import com.gp.geits.utils.Query;
import com.gp.geits.vo.QuestionnaireVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("issueService")
public class IssueServiceImpl extends ServiceImpl<IssueDao, IssueEntity> implements IssueService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<IssueEntity> page = this.page(
                new Query<IssueEntity>().getPage(params),
                new QueryWrapper<IssueEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void addQuestionnaire(QuestionnaireVo vo, Integer id) {
        List<IssueEntity> issueEntityList = vo.getIssueEntityList();

        for (IssueEntity entity : issueEntityList){
            entity.setQuestionnaireId(id);
        }

        saveBatch(issueEntityList);
    }

    @Override
    public List<IssueEntity> getQuestionnaireByName(Integer questionnaireId) {
        return baseMapper.selectList(new QueryWrapper<IssueEntity>()
                .eq("questionnaire_id", questionnaireId));
    }

}